# makfile configuration
NAME            = libradio

ELF		= elf/radio.elf

UTILS_DIR	= utils
DRIVER_DIR	= driver
CONTROL_DIR	= control
MODE_DIR	= mode
OS_DIR		= os

OBJECTS         = 	$(UTILS_DIR)/utils.o \
			$(DRIVER_DIR)/lcd.o \
			$(DRIVER_DIR)/led.o \
			$(DRIVER_DIR)/volume.o \
			$(DRIVER_DIR)/frequence.o \
			$(DRIVER_DIR)/flashMemory.o \
			$(DRIVER_DIR)/irda.o \
			$(UTILS_DIR)/display.o \
			$(CONTROL_DIR)/ctrl_vol.o \
			$(CONTROL_DIR)/ctrl_freq.o \
			$(CONTROL_DIR)/ctrl_station.o \
			$(CONTROL_DIR)/ctrl_mem.o \
			$(MODE_DIR)/mode_freq.o \
			$(MODE_DIR)/mode_vol.o \
			$(MODE_DIR)/mode_station.o \
			$(MODE_DIR)/menu.o \
			$(MODE_DIR)/stats.o \
			$(MODE_DIR)/simon.o \
			radio.o

#should be 149, waiting for wsim
CPU             = msp430x149

# Includes necessaire pour les appels systemes
OSDIR		= ./os
RTOSDIR		= $(OSDIR)/OS/
PORTDIR         = $(OSDIR)/Ports/MSP430/F1611/GNU

INCDIRS		= -I$(OSDIR) -I$(PORTDIR) -I$(RTOSDIR)

# default flags for compilation
DEFAULT_FLAGS	= -mmcu=${CPU} $(INCDIRS) -Wall -g

# use when building the entire program
CFLAGS          = ${DEFAULT_FLAGS}

#switch the compiler (for the internal make rules)
CC              = msp430-gcc
AR		= msp430-ar
RM		= rm

.PHONY: all FORCE clean

#all should be the first target. it's built when make is run without args
all: ${NAME}.a

#additional rules for files
${NAME}.a: deps radio.o
	${RM} -f $@; \
	${AR} q $@ ${OBJECTS}; \
	${AR} s $@; \
	cd $(OS_DIR) && $(MAKE)
	
deps: 
	@(cd $(MODE_DIR) && $(MAKE)); 

clean: 
	@((cd $(MODE_DIR) && $(MAKE) clean);(cd $(OS_DIR) && $(MAKE) clean)); \
	rm -f ${NAME}.a

run:
	wsim-otsetre --ui ${ELF}
#backup archive
dist:
	tar czf radio.tgz driver utils control os Makefile

download: all
	msp430-jtag -e ${ELF}

#dummy target as dependecy if something has to be build everytime
FORCE:

radio.c: $(DRIVER_DIR)/frequence.h $(MODE_DIR)/menu.h


.o: .c


